package vip.liux.backend.infrastructure.jpa.pay;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import vip.liux.contracts.models.pay.PayDemoWithdraw;
import vip.liux.contracts.repositories.pay.PayDemoWithdrawRepository;
import vip.liux.contracts.shared.enums.pay.PayDemoWithdrawStatus;

import java.time.LocalDateTime;

public interface PayDemoWithdrawJpaRepository extends JpaRepository<PayDemoWithdraw, Long>, PayDemoWithdrawRepository, JpaSpecificationExecutor<PayDemoWithdraw> {

    @Transactional
    @Modifying
    @Override
    @Query("update PayDemoWithdraw set payTransferNo = :payTransferNo where id = :id and status = :whereStatus")
    void updateByIdAndStatus(Long id, PayDemoWithdrawStatus whereStatus, String payTransferNo);

    @Transactional
    @Modifying
    @Override
    @Query("update PayDemoWithdraw set status = :status, transferTime = :transferTime, transferErrorMsg = :transferErrorMsg where id = :id and status = :whereStatus")
    void updateByIdAndStatus(Long id, PayDemoWithdrawStatus whereStatus, PayDemoWithdrawStatus status, LocalDateTime transferTime, String transferErrorMsg);

    @Transactional
    @Modifying
    @Override
    @Query("update PayDemoWithdraw set status = :status, transferErrorMsg = :transferErrorMsg where id = :id and status = :whereStatus")
    int updateByIdAndStatus(Long id, PayDemoWithdrawStatus whereStatus, PayDemoWithdrawStatus status, String transferErrorMsg);
}